define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'wxnew/jzsq/index' + location.search,
                    add_url: 'wxnew/jzsq/add',
                    edit_url: 'wxnew/jzsq/edit',
                    del_url: 'wxnew/jzsq/del',
                    multi_url: 'wxnew/jzsq/multi',
                    import_url: 'wxnew/jzsq/import',
                    table: 'open_mp',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                showToggle: false, // 浏览模式切换
                showColumns: true, // 允许选择显示字段
                showExport: true, // 导出选项
                exportDataType: "basic", //导出当前页
                exportTypes: ['excel'],
                searchFormVisible: false, // 通用搜索 默认是否显示
                search: false, // 是否关闭搜索
                trimOnSearch: true, // 自动删除搜索空格
                pageList: [10, 20, 30, 50],
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [{
                            checkbox: true
                        },
                        {
                            field: 'id',
                            title: __('Id')
                        },
                        {
                            field: 'wx_app_id',
                            title: __('Wx_app_id'),
                            operate: 'LIKE'
                        },
                        {
                            field: 'nick_name',
                            title: __('Nick_name'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'user_name',
                            title: __('User_name'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'service_type_info',
                            title: __('Service_type_info'),
                            searchList: {
                                "1": __('Service_type_info 1'),
                                "2": __('Service_type_info 2'),
                                "0": __('Service_type_info 0')
                            },
                            formatter: Table.api.formatter.normal
                        },
                        {
                            field: 'principal_name',
                            title: __('Principal_name'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'image',
                            title: __('Image'),
                            operate: false,
                            events: Table.api.events.image,
                            formatter: Table.api.formatter.image
                        },
                        {
                            field: 'status',
                            title: __('Status'),
                            searchList: {
                                "1": __('Status 1'),
                                "0": __('Status 0'),
                                "14": __('Status 14'),
                                "16": __('Status 16'),
                                "18": __('Status 18'),
                                "19": __('Status 19')
                            },
                            formatter: Table.api.formatter.normal
                        },
                        {
                            field: 'createtime',
                            title: __('Createtime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });
            $('.wx-auth').click(function () {
                var loadingIdx = layer.load(1, {
                    shade: [0.1, '#000']
                });



                setTimeout(function () {
                    layer.close(loadingIdx)
                }, 5000);
                $.post({
                    url: "wxnew/jzsq/getAuthUrl",
                }, function (data) {
                    layer.close(loadingIdx)
                    Fast.api.open(data.data, "授权", {
                        callback: function () {
                            $('.btn-refresh').trigger('click');
                        }
                    });
                });
            })
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});